<template>
  <div>
    <Appheader :parentToChild="ymname" @c_addrname="parentFn" @refresh="refresh"></Appheader>
    <div class="content" v-loading="loading">
      <div class="choose_classify">
        <div class="classify1" v-if="type == 0">
          <p>地&nbsp;&nbsp;区:</p>
          <ul>
            <li
              class="addr_li"
              v-for="(addr_list,addr_index) in address"
              :key="addr_index"
              :class="c_addr==addr_list.addname?'bg':''"
              @click="choose_addr(addr_list.addname)"
            >{{addr_list.addname}}</li>
          </ul>
        </div>
        <div class="classify2" v-if="type == 1">
          <p>学&nbsp;&nbsp;校:</p>
          <ul>
            <li
              class="maj_li"
              v-for="(maj_list,maj_index) in Schoollist"
              :key="maj_index"
              :class="c_maj==maj_list.name?'bg':''"
              @click="choose_maj(maj_list.name,maj_list.id)"
            >{{maj_list.name}}</li>
          </ul>
        </div>
      </div>
      <ul class="list_ul">
        <li class="list_li" v-for="(list,index) in listarry" :key="index">
          <img :src="list.photo" alt />
          <div class="list_li_div">
            <div class="li_div_a">
              <div class="hidden">{{list.title}}</div>
            </div>
            <div class="li_div_b hidden3" v-html="list.content.slice(0,260)"></div>
            <div class="li_div_c">
              <p>{{list.createtime}}</p>
              <div @click="see_more(list.id)">了解更多</div>
            </div>
          </div>
        </li>
        <div class="page" v-if="total!=0">
          <div class="page_a" @click="handleCurrentChange(1)">首页</div>
          <el-pagination
            background
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage"
            layout="prev, pager, next"
            :total="total"
            :page-size="5"
          ></el-pagination>
          <div class="page_a" @click="handleCurrentChange('w')">尾页</div>
        </div>
        <div v-else class="tip2">
          <img src="../../assets/none.png" alt />
        </div>
      </ul>
    </div>
    <Appfooter></Appfooter>
  </div>
</template>

<script>
import Appheader from "../pindaoye/headers";
import Appfooter from "../footer";
import address from "../../../static/address";
import { mationlist, formationTypelist, ykSchoollist } from "../../api/index";
export default {
  props: {},
  data() {
    return {
      ymname: "艺考资讯",
      address: address,
      c_addr: "全国",
      c_addrs: "全国",
      c_maj: "全部",
      c_maj_id: "",
      zixunType: {
        id: "",
        name: "全部"
      },
      loading: true,
      currentPage: 1,
      total: 0, //列表总数
      pagenum: 1, //请求的页数
      pagesize: 5, //请求的数量
      listarry: [], //请求的数据
      tuijian: "",
      // 学校列表
      Schoollist: [],
      type: 0,
      profationId: "",
      zixuntype:''
    };
  },
  computed: {},
  created() {
    sessionStorage.setItem("nowPage", "yikaozixunPd");
    if (this.$route.params.type) {
      this.type = this.$route.params.type;
      this.profationId = this.$route.params.pId||this.$route.params.profationId;
      localStorage.setItem("type", this.type);
      localStorage.setItem("profationId", this.profationId);
    } else {
      //console.log(this.type);
      this.type = localStorage.getItem("type");
      this.profationId = localStorage.getItem("profationId");
    }
    sessionStorage.setItem("izixun", this.type);
    if (
      this.profationId == "" ||
      this.profationId == null ||
      this.profationId == undefined
    ) {
      this.profationId = localStorage.getItem("profationId");
    }
    if (this.$route.params.zixuntype) {
      this.zixuntype = this.$route.params.zixuntype;
      localStorage.setItem("zixuntype", this.zixuntype);
    }else {
      //console.log(this.type);
      this.zixuntype = localStorage.getItem("zixuntype");
    }
  },
  mounted() {
    ykSchoollist()
      .then(res => {
        // console.log(res);
        if (res.data.code == 0) {
          res.data.rows.unshift(this.zixunType);
          this.Schoollist = res.data.rows;
        }
      })
      .catch(err => {});
    this.post();
  },
  watch: {},
  methods: {
    refresh(res) {
      this.type = res.type;
      this.profationId = res.id;
      localStorage.setItem("type", this.type);
      localStorage.setItem("profationId", this.profationId);
      sessionStorage.setItem("izixun", this.type);
      sessionStorage.setItem("izixunid", this.profationId);
      this.post();
    },
    choose_school(item, id) {
      this.c_addr = item;
      this.c_addrs = "";
      this.pagenum = 1;
      this.currentPage = 1;
      this.schoolid = id;
      this.post();
    },
    post() {
      var k = "";
      if (this.c_addr == "全国") {
        k = "";
      } else {
        k = this.c_addr;
      }
      let msg;
      if (this.type == "0") {
        msg = {
          itype: this.type,
          type: this.profationId,
          iaddr: k,
          zixuntype:this.zixuntype,
          pageNum: this.pagenum,
          pageSize: this.pagesize
        };
      } else {
        msg = {
          itype: this.type,
          type: this.profationId,
          ischool: this.c_maj_id,
          zixuntype:this.zixuntype,
          pageNum: this.pagenum,
          pageSize: this.pagesize
        };
      }
      // console.log(msg);
      mationlist(this.qs(msg))
        .then(res => {
          if (res.data.code == 0) {
            if (res.data.rows.length != 0) {
              for (let i = 0; i < res.data.rows.length; i++) {
                res.data.rows[i].createtime = res.data.rows[i].createtime.split(
                  " "
                )[0];
              }
            }
            this.listarry = res.data.rows;
            this.total = res.data.total;
          }
          this.loading = false;
        })
        .catch(e => {});
    },
    choose_addr(item) {
      this.c_addr = item;
      this.c_addrs = item;
      this.pagenum = 1;
      this.currentPage = 1;
      this.schoolid = "";
      this.post();
    },
    choose_maj(item, id) {
      if (item.indexOf("全部") != -1) {
        this.c_maj_id = "";
      } else {
        this.c_maj_id = id;
      }
      this.c_maj = item;
      this.pagenum = 1;
      this.currentPage = 1;
      this.post();
    },
    handleCurrentChange(val) {
      if (val == "w") {
        this.pagenum = Math.ceil(this.total / this.pagesize);
      } else {
        this.pagenum = val;
      }
      this.currentPage = this.pagenum;
      this.loading = true;
      this.post();
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    },
    //查看更多
    see_more(list_id) {
      sessionStorage.setItem("nowPage", "yikaozixunDetailPd");
      this.$router.push({
        name: "zixunDetails",
        params: {
          id: list_id
        }
      });
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    },
    parentFn(data) {
      this.choose_addr(data);
    }
  },
  components: { Appheader, Appfooter }
};
</script>

<style scoped>
.content {
  width: 1200px;
  margin: 0 auto;
}
/* choose_classify */
.choose_classify {
  background: #363640;
  border-radius: 10px;
  padding: 18px 72px 11px 36px;
}
.choose_classify > div {
  display: flex;
}
.choose_classify > div > p {
  margin-top: 2px;
}
.choose_classify > div > p,
.choose_classify li {
  font-size: 14px;
  color: #fff;
}
.choose_classify > div > ul {
  flex-wrap: wrap;
  display: flex;
}
.choose_classify li {
  cursor: pointer;
  height: 24px;
  border-radius: 12px;
  text-align: center;
  line-height: 24px;
  margin-left: 13px;
  margin-bottom: 11px;
  padding: 0 10px;
  color: #9799a5;
}
.choose_classify li:hover{
  color: #c9a750;
}
.bg {
  border:1px solid #c9a750;
  color: #c9a750;
}
.list_li {
  padding: 38px 75px 24px 8px;
  box-sizing: border-box;
  display: flex;
}
.list_li > img {
  width: 284px;
  height: 165px;
  margin-right: 35px;
  border-radius: 20px;
}
.li_div_a {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.li_div_a > div {
  width: 580px;
  font-size: 18px;
  color: #fff;
}
.li_div_a > p {
  font-size: 14px;
  color: #8f919e;
}
.li_div_b {
  margin-top: 13px;
  font-size: 14px;
  color: #8f919e;
  line-height: 26px;
  width: 795px;
}
.li_div_c {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.li_div_c p{
  color: #a1a3af;
  font-size: 12px;
}
.li_div_c > div {
  width: 99px;
  height: 30px;
  border-radius: 30px;
  border: 1px solid #c7a750;
  font-size: 14px;
  color: #c7a750;
  line-height: 30px;
  text-align: center;
  margin-top: 5px;
  cursor: pointer;
}
.list_li:hover {
  /* border-top: 1px solid #c9a253; */
  /* border-bottom: 1px solid #c9a253; */
}
/* page */
.page {
  display: flex;
  justify-content: center;
  margin-top: 40px;
  margin-bottom: 75px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.page >>> .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #c9a253 !important;
}
.page >>> .el-pager li,
.page >>> .btn-next,
.page >>> .btn-prev {
  width: 34px;
  height: 34px;
  padding: 0;
  line-height: 34px;
  text-align: center;
  border-radius: 5px;
}
.page_a {
  width: 34px;
  height: 34px;
  background: rgba(243, 243, 243, 1);
  border-radius: 5px;
  font-size: 12px;
  color: #333;
  line-height: 34px;
  text-align: center;
}
.page_a:hover {
  background: #c9a253;
  color: #fff;
}
</style>
